<#assign baseURL = springMacroRequestContext.getContextPath() />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>拓深科技</title>
<#include "./css.ftl">
</head>
<body>
<div id="wrapper">

<#include "./left_nav.ftl">

    <div id="page-wrapper" class="gray-bg dashbard-1 animated fadeInRight">
    <#include "./top_nav.ftl">
        <div class="row wrapper border-bottom white-bg page-heading">
            <div class="col-lg-9">
                <h2>误报记录</h2>
                <ol class="breadcrumb">
                    <li>
                        消防联网可视化系统
                    </li>
                    <li class="active">
                        误报记录
                    </li>
                </ol>
            </div>
        </div>
        <div class="wrapper wrapper-content">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li><a data-toggle="tab" href="#tab-1">已确认</a></li>
                    <li class="active"><a data-toggle="tab" href="#tab-2">未确认</a></li>
                </ul>
                <div class="tab-content">
                    <div id="tab-1" class="tab-pane">
                        <div class="panel-body">
                            <table class="table table-striped table-bordered table-hover " id="falseConfirmTable" cellspacing="0" width="100%">
                                <thead>
                                <tr>
                                    <th>报警时间</th>
                                    <th>区域</th>
                                    <th>建筑物</th>
                                    <th>楼层</th>
                                    <th>值班室电话</th>
                                    <th>用户信息传输装置名称</th>
                                    <th>用户信息传输装置IP</th>
                                    <th>监测点名称</th>
                                    <th>传感器类别</th>
                                    <th>报警类型</th>
                                    <th>确认时间</th>
                                    <th>确认用户</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>
                    </div>
                    <div id="tab-2" class="tab-pane active">
                        <div class="panel-body">
                            <div class="col-md-12" style="padding-left: 0;">
                                <div class="col-md-2" style="margin-bottom: 5px;padding-left: 0;">
                                    <button id="refreshBtn" type="button" class="btn btn-block btn-success"><i class="fa fa-refresh"></i>&nbsp;刷新</button>
                                </div>
                            </div>
                            <table class="table table-striped table-bordered table-hover " id="falseNoneConfirmTable" cellspacing="0" width="100%">
                                <thead>
                                <tr>
                                    <th>报警时间</th>
                                    <th>地理位置</th>
                                    <th>值班室电话</th>
                                    <th>用户信息传输装置名称</th>
                                    <th>用户信息传输装置IP</th>
                                    <th>监测点名称</th>
                                    <th>传感器类别</th>
                                    <th>报警类型</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    <#include "./bottom_nav.ftl">
    </div>

</div>


<#include "./js.ftl">

<script>
    $(function(){
        socketInit("//" + getURL() + "${baseURL}")
    });

    var falseConfirmTable = $('#falseConfirmTable').DataTable({
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        },
        ajax: "${baseURL}/alarm/getConfirmFalseData",
        columns:[
            {"data":"alarm_time","render":function(data, type, row, meta){
                return showTime(data);
            }},
            {"data":"geo_1_name"},
            {"data":"geo_2_name"},
            {"data":"geo_3_name"},
            {"data":"phone"},
            {"data":"device_name"},
            {"data":"device_ip_str"},
            {"data":"monitor_name"},
            {"data":"sensor_name"},
            {"data":"dev_status","render":function(data, type, row, meta){
                return "误报";
            }},
            {"data":"confirm_time","render":function(data, type, row, meta){
                return showTime(data);
            }},
            {"data":"user"},
            {"data":"id","render":function(data, type, row, meta){
                return '<div class="col-md-12" style="padding: 0 0 0 0"><button <#if (role_type_id > 1)> disabled </#if> style="padding: 0 0 0 0" type="button" onclick="deleteRecord('+data+')" class="btn btn-block btn-danger"><i class="fa fa-trash"></i>删除</button></div>';
            }},
        ],
        destroy: true,
        serverSide: true,
        searching:false,
        bSort:false
    });

    function deleteRecord(id){
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            url: "${baseURL}/alarm/deleteById?id=" + id,
            async: false,
            success:function(data){
                if(data.code === 0){
                    swal({
                        title: "删除成功。",
                        type: "success"
                    },function(){
                        falseConfirmTable.ajax.reload();
                    });
                }else{
                    swal({
                        title: "删除失败。",
                        type: "error"
                    });
                }
            },
            error:function(xhr, status, error){
                console.log(xhr.responseText)
                swal({
                    title: "请求异常。",
                    type: "error"
                })
            }
        });
    }

    var falseNoneConfirmTable = $('#falseNoneConfirmTable').DataTable({
        language: {
            "sProcessing": "处理中...",
            "sLengthMenu": "显示 _MENU_ 项结果",
            "sZeroRecords": "没有匹配结果",
            "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
            "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
            "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
            "sInfoPostFix": "",
            "sSearch": "搜索:",
            "sUrl": "",
            "sEmptyTable": "表中数据为空",
            "sLoadingRecords": "载入中...",
            "sInfoThousands": ",",
            "oPaginate": {
                "sFirst": "首页",
                "sPrevious": "上页",
                "sNext": "下页",
                "sLast": "末页"
            },
            "oAria": {
                "sSortAscending": ": 以升序排列此列",
                "sSortDescending": ": 以降序排列此列"
            }
        },
        ajax: "${baseURL}/alarm/getNoneConfirmFalseData",
        columns:[
            {"data":"alarm_time"},
            {"data":"geo"},
            {"data":"phone"},
            {"data":"device_name"},
            {"data":"ip"},
            {"data":"name"},
            {"data":"sensor_name"},
            {"data":"dev_status","render":function(data, type, row, meta){
                return "误报";
            }},
            {"data":"alarm_origin_id","render":function(data, type, row, meta){
                return '<div class="col-md-12" style="padding: 0 0 0 0"><button style="padding: 0 0 0 0" type="button" onclick="confirmRecord('+data+')" class="btn btn-block btn-warning"><i class="fa fa-check"></i>&nbsp;确认</button></div>';
            }},
        ],
        destroy: true,
        order:[["0","desc"]]
    });

    function confirmRecord(id){
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            url: "${baseURL}/alarm/confirm?alarm_id=" + id,
            async: false,
            success:function(data){
                if(data.code === 0){
                    swal({
                        title: "确认成功。",
                        type: "success"
                    },function(){
                        falseNoneConfirmTable.ajax.reload();
                        falseConfirmTable.ajax.reload();
                        refreshTip();
                    });
                }else{
                    swal({
                        title: "确认失败。",
                        type: "error"
                    });
                }
            },
            error:function(xhr, status, error){
                console.log(xhr.responseText)
                swal({
                    title: "请求异常。",
                    type: "error"
                })
            }
        });
    }

    $("#refreshBtn").click(function(){
        falseNoneConfirmTable.ajax.reload();
    });

    function showTime(unix_time) {
        var date = new Date(unix_time * 1000);
        var year = date.getFullYear().toString();
        var month = (date.getMonth() + 1).toString();
        if(month.length < 2) month = '0' + month;
        var day = date.getDate().toString();
        if(day.length < 2) day = '0' + day;
        var h = date.getHours().toString();
        if(h.length < 2) h = '0'+ h;
        var m = date.getMinutes().toString();
        if(m.length < 2) m = '0'+ m;
        var s = date.getSeconds().toString();
        if(s.length < 2) s = '0'+ s;
        return year + '-' + month + '-' + day + ' ' + h + ":" + m +":" + s;
    }

    function refreshTip(){
        $.ajax({
            type: "GET",
            contentType: "application/json",
            dataType: "json",
            url: "${baseURL}/alarm/getCount",
            success:function(data){
                if(data.data.fireLog === 0) {
                    $("#fireLog").css({"display":"none"});
                } else{
                    $("#fireLog").html(data.data.fireLog);
                }
                if(data.data.faultLog === 0) {
                    $("#faultLog").css({"display":"none"});
                } else{
                    $("#faultLog").html(data.data.faultLog);
                }
                if(data.data.falseLog === 0) {
                    $("#falseLog").css({"display":"none"});
                } else{
                    $("#falseLog").html(data.data.falseLog);
                }
                if(data.data.totalLog === 0) {
                    $("#totalLog").css({"display":"none"});
                } else{
                    $("#totalLog").html(data.data.totalLog);
                }
            }
        });
    }

</script>
</body>
</html>